package frame1;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;

public class Demo4 extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Demo4 frame = new Demo4();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Demo4() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		
		JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 3, 3));
		p1.add(new JLabel("1"));
		p1.add(new JLabel("2"));
		p1.add(new JLabel("3"));
		p1.add(new JLabel("4"));
		p1.add(new JLabel("5"));
		JPanel p2 = new JPanel(new GridLayout(3, 3, 3, 3));
		for(int i = 0; i < 9; i++){
			JButton btn = new JButton("btn" + i);
			
			btn.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					System.out.println("点击了按钮:" + ((JButton)e.getSource()).getText());
				}
			});
			p2.add(btn);
		}
		JTabbedPane tabs = new JTabbedPane(JTabbedPane.LEFT);
		tabs.add("面板1", p1);
		tabs.add("面板2", p2);
		
		contentPane.add(tabs);
		
		setContentPane(contentPane);
	}

}
